/* News Article Script
 *
 * predefined variables are:
 *     th_url_blog
 *     th_jumlah_post
 *     th_warna_teks
 *     th_warna_latar
 *     th_backlink
 */
var th_entries; var th_feed;
var th_feed_url = th_url_blog.match(/\/$/) ? th_url_blog : th_url_blog+"/";
th_feed_url += "feeds/posts/default";

function th_createEntries(){
    var entries = th_feed.entry;
    var entriesArr = [];
    for(var i=0; i<th_jumlah_post; i++){
        var entry = entries[i];
        var entryObj = new Object();
        entryObj.title = entry.title.$t;
        entryObj.href  = th_getHref(entry.link);
        entriesArr.push(entryObj);
    }
    return entriesArr;
}
function th_getBlogTitle(){
    return th_feed.title.$t;
}
function th_getBlogURL(){
    return th_getHref(th_feed.link);
}
function th_getHref(links){
    for(var i=0; i<links.length; i++){
        var link = links[i];
        if(link.rel == "alternate"){return link.href;}
    }
    return null;
}
function th_start(json){
    th_feed = json.feed;
    th_entries = th_createEntries();
    th_writeStyle();
    th_writeContent();
}
function th_writeScript(){
    var src = th_feed_url+"?alt=json-in-script&callback=th_start&max-results="+th_jumlah_post;
    
    //var src = "json.php?c=th_start";
    var s = "<script src='"+src+"'></script>";
    document.write(s);
}
function th_writeStyle(){
    var s = "<style type='text/css'>";
    s += "#th_headline{";
    s += "    position:fixed;";
    s += "    "+th_posisi+":0px;";
    s += "    left:0px;";
    s += "    padding:5px;";
    s += "    width:100%;";
    s += "    background:" + th_warna_latar + ";";
    s += "    border:1px solid "+ th_warna_garis + ";";
    s += "}";
    s += "* html #th_headline{position:relative;}";
    s += "</style>";
    document.write(s);
}
function th_writeContent(){
    var s = "<div id='th_headline' title='News Article of "+th_getBlogTitle()+"'>";
    s += "<div style='float:left'>";
    s += " <a href='"+th_feed_url+"'>";
    s += "  <img src='https://lh3.googleusercontent.com/-h5PwWpgB8Jw/TgiACcF1vrI/AAAAAAAAA7Q/zXO3KnLk2YU/s288/news.rss.png'";
    s += " height='20'/>";
    s += " </a>";
    s += "</div>";
    if(th_tampilkan_judul){
        s += "  <div style='float:left; font-size:9px; text-align:right; margin-left:10px;'>";
        s += "    News Article of <br/>";
        s += "    <a href='" + th_getBlogURL() + "'>" + th_getBlogTitle() + "</a>";
        s += "  </div>";
    }
    s += "  <marquee style='float:left; margin-left:10px; width:70%' scrollAmount='3'>";
    for(var i=0; i<th_jumlah_post; i++){
        var th_entry = th_entries[i];
        s += "<a href='"+th_entry.href+"' ";
        s += "onmouseover='this.parentNode.stop()' onmouseout='this.parentNode.start()'";
        s += ">" + th_entry.title + "</a>";
        if(i != th_jumlah_post-1){s += " | ";}
    }
    s += "  </marquee>";
    s += "<div style='float:right; margin-right:10px;'>";
    s += "  <a href='javascript:void(0)' onclick='document.getElementById(\"th_headline\").style.display=\"none\"'>";
    s += "    [x]";
    s += "  </a>";
    s += "</div>";
    if(th_backlink == true | th_backlink == undefined){
        s += "<div style='float:right; font-size:9px; text-align:right; margin-right:10px'>";
        s += "  Widget by<br/>";
        s += "  <a href='http://www.indoblogspot.net'>";
        s += "    Indo Blog";
        s += "  </a>";
        s += "</div>";
    }
    s += "</div>";
    document.write(s);
}
th_writeScript();
